﻿var AnJuKePartial = {};
$(function () {
    $("#BatchDelete").unbind("click");
    $("#BatchDelete").bind("click", function () {
        var objCheck = other.checkCount(true, "#gdList input[ad=ad]:checked", "没有选择任何数据！", "", function () {
            $.OKCancelDialogAgency('<div class="tc">您确定要删除吗？</div>', '删除提示', function () { }, function () {
                var tempAds = $("#gdList input[ad=ad]:checked");
                AnJuKePartial.checkAdKeyIds = "";
                for (var i = 0; i < tempAds.length; i++) {
                    if (i == 0) {
                        AnJuKePartial.checkAdKeyIds += $(tempAds[i]).attr("keyid");
                        continue;
                    }
                    AnJuKePartial.checkAdKeyIds += "," + $(tempAds[i]).attr("keyid");
                }
                var url = "/Advert/delete-anjuke";
                var reqData = {
                    "proIds": AnJuKePartial.checkAdKeyIds
                };
                $.AjaxAgency(url, reqData, function (data) {
                    if (data == "ok") {
                        RefreshAnJuKeNumber();
                        $("#searchForm").submit();
                    }
                    else {
                        $.OKDialogAgency('<div class="tc">' + data + '</div>');
                    }
                });
            }, function () {

            });
        });
    });
    other.selectAll("input[name='chbSelectAll']", "#gdList .checkbox-vertical-middle", AnJuKePartial.SelectAllChange);

    //浮动的工具栏 yjj添加
    var state1 = true; //存储顶部显示的状态
    $(window).scroll(function () {
        if ($(window).scrollTop() > $("#ajaxPages").offset().top) {
            if (state1) {
                //执行浮动层出现后的代码
                $(".fixed-div").show();
                $(".property-bool-tag").addClass("float-edit-toos");
            }
            state1 = false;
        } else {
            if (!state1) {
                //执行浮动层出现前的代码
                $(".fixed-div").hide();
                $(".property-bool-tag").removeClass("float-edit-toos");
            }
            state1 = true;
        }
    });
    var n = $("#gdList th").size();
    for (var i = 0; i < n; i++) {
        $(".fixed-div div").append("<span class='fixed-span'></span>");
        $(".fixed-div div").find(".fixed-span").eq(i).html($("#gdList th").eq(i).html());
        $(".fixed-div div").find(".fixed-span").eq(i).addClass($("#gdList th").eq(i).attr("class"));
        $(".fixed-div div").find(".fixed-span").eq(i).css({ "width": $("#gdList th").eq(i).outerWidth(), "text-align": "center" });
    }
});
//勾选checkbox删除按钮变化
AnJuKePartial.SelectAllChange = function () {
    var checkedCount = 0;
    $("#gdList input[ad=ad]").each(function () {
        if ($(this).attr("checked") == "checked") {
            checkedCount = checkedCount + 1;
        }
    });
    //如果列表中都勾选了，则将全选设为勾选状态
    if ($("#gdList input[ad=ad]").length == checkedCount) {
        $("input[name='chbSelectAll']").attr("checked", true);
    }
    else {
        $("input[name='chbSelectAll']").attr("checked", false);
    }
}